#include "Hooks.h"
#include "WinMacroLib.h"

#ifndef SESSION
#define SESSION

class Session
{
public:
	Session(HINSTANCE instance) : module_instance(instance), hook_handle(NULL),
		getmsg_hook_handle(NULL)
	{
		signature[0] = 'S'; signature[1]= 'A'; signature[2] = 'D'; signature[3] = 'H'; signature[4] = 'U'; signature[5] = '\0';
		signature_length = sizeof(signature);
	}

protected:
	DWORD start_time;
	HHOOK hook_handle;
	HHOOK getmsg_hook_handle;
	HINSTANCE module_instance;

	char signature[6];
	int signature_length;

	void InstallGetMsgHook()
	{
		getmsg_hook_handle = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, NULL, GetCurrentThreadId());
	}

	virtual void SessionStopped() = 0;

public:
	HHOOK GetHookHandle() { return hook_handle; }
	HHOOK GetGetMessageHookHandle () { return getmsg_hook_handle; }
	HINSTANCE GetModuleInstance() { return module_instance; }

	virtual void SessionCancelled()
	{
		UninstallHook(hook_handle);
		UninstallHook(getmsg_hook_handle);
		SessionStopped();
	}

	virtual ~Session(){}

private:
	void UninstallHook(HHOOK &hook)
	{
		if (hook)
		{
			//Remove the hook
			UnhookWindowsHookEx(hook);
			hook = NULL;
		}
	}
};

#endif